export default {
    props: {},
    data() {
            // @VExportData-Start
            return {
                row: {
                    item_id: null,
                    pack_id: null,
                    pack_item_id: null,
                    item_name: null,
                    manufacturer: null,
                    item_desc: null,
                    item_code: null,
                    pack_name: null,
                    pack_level: null,
                    pack_meas: null,
                    volume: null,
                    weight: null,
                    lot01: null,
                    lot02: null,
                    lot03: null,
                    lot04: null,
                    lot05: null,
                    lot06: null,
                    lot07: null,
                    lot08: null,
                    lot09: null,
                    lot10: null,
                    lot11: null,
                    lot12: null,
                    remark: null,
                },
                disp: {
                    item_desc: null,
                    qty: null,
                },
                vjson: {
                    layout: 'DefaultLayout',
                    items: [
                        {
                            xtype: 'form',
                            colsOfRow: '3',
                            items: [
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '商品ID',
                                    bind: {
                                        value: '{row.item_id}',
                                    },
                                    weight: 1,
                                    lookup: {},
                                    hidden: false,
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '包装ID',
                                    bind: {
                                        value: '{row.pack_id}',
                                    },
                                    weight: 1,
                                    lookup: {},
                                    hidden: false,
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: 'pack_item_id',
                                    bind: {
                                        value: '{row.pack_item_id}',
                                    },
                                    weight: 1,
                                    lookup: {},
                                    hidden: false,
                                },
                                {
                                    xtype: 'combogrid',
                                    fieldLabel: '商品',
                                    bind: {
                                        value: '{row.item_name}',
                                    },
                                    param: {},
                                    widget: 'ItemSearch',
                                    lookup: {
                                        item_id: '{row.item_id}',
                                        item_name: '{row.item_name}',
                                        manufacturer: '{row.manufacturer}',
                                        sku_desc: '{disp.item_desc}',
                                        item_desc: '{row.item_desc}',
                                        item_code: '{row.item_code}',
                                    },
                                    reference: 'ctl_item_name',
                                    required: true,
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '商品描述',
                                    bind: {
                                        value: '{row.item_desc}',
                                    },
                                    lookup: {},
                                    disabled: true,
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '生产厂家',
                                    bind: {
                                        value: '{row.manufacturer}',
                                    },
                                    disabled: true,
                                },
                                {
                                    xtype: 'combogrid',
                                    fieldLabel: '包装',
                                    bind: {
                                        value: '{row.pack_name}',
                                    },
                                    lookup: {
                                        pack_id: '{row.pack_id}',
                                        pack_item_id: '{row.pack_item_id}',
                                        pack_name: '{row.pack_name}',
                                        pack_level: '{row.pack_level}',
                                        pack_meas: '{row.pack_meas}',
                                        volume: '{row.volume}',
                                        weight: '{row.weight}',
                                    },
                                    param: {
                                        item_id: '{row.item_id}',
                                    },
                                    widget: 'PackageItemsSearch',
                                    required: true,
                                },
                                {
                                    xtype: 'combo',
                                    fieldLabel: '收货单位',
                                    bind: {
                                        value: '{row.pack_level}',
                                    },
                                    dataType: 2,
                                    dataDict: 'packLevel',
                                    lookup: {},
                                    readonly: false,
                                    disabled: true,
                                },
                                {
                                    xtype: 'staticfield',
                                    fieldLabel: 'pack_meas',
                                    bind: {
                                        value: '{row.pack_meas}',
                                        text: '{staticfield1_text}',
                                    },
                                    lookup: {},
                                    hidden: true,
                                },
                                {
                                    xtype: 'staticfield',
                                    fieldLabel: 'item_code',
                                    bind: {
                                        value: '{row.item_code}',
                                        text: '{staticfield2_text}',
                                    },
                                    lookup: {},
                                    hidden: true,
                                },
                            ],
                            reference: 'form1',
                        },
                        {
                            xtype: 'divider',
                            content: '数量',
                            contentPosition: 'left',
                        },
                        {
                            xtype: 'form',
                            colsOfRow: '3',
                            items: [
                                {
                                    xtype: 'staticfield',
                                    fieldLabel: '收货数量(主单位)',
                                    bind: {
                                        value: '',
                                        text: '{staticfield3_text}',
                                    },
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '收货数量(收货单位)',
                                    bind: {
                                        value: '{disp.qty}',
                                    },
                                },
                            ],
                            reference: 'form2',
                        },
                        {
                            xtype: 'divider',
                            content: '批属性',
                            contentPosition: 'left',
                        },
                        {
                            xtype: 'form',
                            colsOfRow: '3',
                            items: [
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '批属性01',
                                    bind: {
                                        value: '{row.lot01}',
                                    },
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '批属性02',
                                    bind: {
                                        value: '{row.lot02}',
                                    },
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '批属性03',
                                    bind: {
                                        value: '{row.lot03}',
                                    },
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '批属性04',
                                    bind: {
                                        value: '{row.lot04}',
                                    },
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '批属性05',
                                    bind: {
                                        value: '{row.lot05}',
                                    },
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '批属性06',
                                    bind: {
                                        value: '{row.lot06}',
                                    },
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '批属性07',
                                    bind: {
                                        value: '{row.lot07}',
                                    },
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '批属性08',
                                    bind: {
                                        value: '{row.lot08}',
                                    },
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '批属性09',
                                    bind: {
                                        value: '{row.lot09}',
                                    },
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '批属性10',
                                    bind: {
                                        value: '{row.lot10}',
                                    },
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '批属性11',
                                    bind: {
                                        value: '{row.lot11}',
                                    },
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '批属性12',
                                    bind: {
                                        value: '{row.lot12}',
                                    },
                                },
                            ],
                            reference: 'form3',
                        },
                        {
                            xtype: 'divider',
                            content: '其他',
                            contentPosition: 'left',
                        },
                        {
                            xtype: 'form',
                            colsOfRow: '3',
                            items: [
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '体积',
                                    bind: {
                                        value: '{row.volume}',
                                    },
                                    lookup: {},
                                    required: true,
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '毛重',
                                    bind: {
                                        value: '{row.weight}',
                                    },
                                    required: true,
                                },
                                {
                                    xtype: 'textfield',
                                    fieldLabel: '备注',
                                    bind: {
                                        value: '{row.remark}',
                                    },
                                },
                            ],
                            reference: 'form4',
                        },
                        {
                            xtype: 'toolbar',
                            items: [
                                {
                                    xtype: 'button',
                                    text: '添加',
                                    listeners: {
                                        click: '{button1_click}',
                                    },
                                    iconCls: 'antd SaveFilled',
                                    type: 'primary',
                                    plain: true,
                                    lookup: {},
                                },
                                {
                                    xtype: 'button',
                                    text: '关闭',
                                    listeners: {
                                        click: '{button2_click}',
                                    },
                                },
                            ],
                            lookup: {},
                            reference: 'tb',
                            alignRight: true,
                        },
                    ],
                    height: '',
                    title: 'ASN明细',
                    footerReference: 'tb',
                    listeners: {
                        onMounted: '{onMounted}',
                    },
                },
            }
            //@VExportData-End
            
        },
    methods: {
        onMounted() {
            // parseFloat(this.disp.qty || '0') * parseFloat(this.row.pack_meas || '0')
        },
        button1_click() {
            Promise.all([
                this.refs.form1.validate(),
                this.refs.form2.validate(),
                this.refs.form3.validate(),
                this.refs.form4.validate()
            ]).then(res=>{
                if(typeof this.$props._input?.appendRow === 'function'){
                    this.$props._input.appendRow({
                        row: {
                            order_qty: parseFloat(this.disp.qty || '0') * parseFloat(this.row.pack_meas || '0'),
                            ...this.row
                        }
                    })
            
                    this.row = {}
                    this.disp = {}
                    this.refs.ctl_item_name.focus()
                }
            })
            
        },
        button2_click() {
            this.close()
        },
    },
    computed: {
        staticfield1_text() {
            return this.row.pack_meas
        },
        staticfield2_text() {
            return this.row.pack_meas
        },
        staticfield3_text() {
            return '' + (parseFloat(this.disp.qty || '0') * parseFloat(this.row.pack_meas || '0'))
        },
    },
}